package dsaa;

import java.util.Arrays;

public class Test {

    public static void main(String[] args) {
        int n = 5000;
        long[] array = new long[n*n];
        int index = 0;
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=n;j++) {
                array[index++] = fx(i, j);
            }
        }
        Arrays.sort(array);
        int min = 1;
        //System.out.println(Arrays.toString(array));
        System.out.println(array[min-1]);
    }

    public static long fx(int i,int j) {
        long fx = (long) Math.pow(i, 2) + 12345 * i + (long) Math.pow(j, 2) - 12345 * j + i * j;
        return fx;
    }

}
